Useful snippets

    dispatcher is null

    2023-10-29

    Prøv å npm linke react

    1

    DISPATCHER IS NULL ved app med og npm link library

    First off: prøv

    # i app
    rm package-lock.json
    rm -rf node_modules
    npm i
    # i library prosjektet
    npm link ../../app/node_modules/react # <--- nødvendig
    npm run build # <--- nødvendig
    # i app
    npm link @library/package
    ^C
    npm run dev

    Second: Toggle av og på det kommenterte nedenfor. Restart server mellom hver gang

    // const path = require('path');
    

    /** @type {import('next').NextConfig} / const nextConfig = { // webpack: { // alias: { // react: path.resolve('./node_modules/react'), // }, // }, async rewrites() { return [ // Rewrite everything else to use pages/index { source: "/:path", destination: "/", }, ]; }, };

    module.exports = nextConfig;


    Kan ikke brue react hooks i react component library? Får du dispatcher is null? Eller noe a la cannot use usestate of null?

    Da er det sikkert noe multiple react-versjoner greier som er trøbbelet. Du kan fikse dette ved å legge til react og react-dom som peerDependencies i library's package.json

    "peerDependencies": {
    "bootstrap": ">=5.2.3",
    "react": "$react",
        "react-dom": "$react"
    },

    Eller fjern package-lock.json, node_modules og reinstaller alle packages

    npm link library

    2024-01-06

    See if npm link works

    Run npm run build in the library. See if it updates the app.

    If stuff doesn't update in app, try

    • Restart app's dev server
    • Try as suggested in response from npm cache clean:
    npm install --cache /tmp/empty-cache

    Then restart app dev servers

    • npm unlink @scope/library on both sides and re-link

    If app cant find css

    attempting to import css from app (like with bootstrap css) does not always work for some reason

    inject css into js so that the package imports css by itself

    Reference

    When npm link works, npm ls @scope/package should return:

    app@0.1.0 /home/user/code/app
    └── @scope/package@0.1.0 extraneous -> ./../packages/package-components-project
    

    npm link refuses to go away | clear npm cache

    2024-01-06

    1. Try

    Maybe unlink package?

    npm unlink @scope/package

    clear / swap out cache on either project

    npm install --cache /tmp/empty-cache

    restart all servers

    1. try uninstalling globally and reinstalling dependency:
    sudo npm rm --global @scope/library
    npm rm --global @scope/library
    npm ls --global @scope/library
    npm uninstall @scope/library
    npm i @scope/librayr@latest --save-exact

    try deleting package.json

    try restarting servers???